Conditions | 1 |
Paths | 27 |
Total Lines | 89 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* global API */ |
||
36 | .controller('SettingsCtrl', ['$scope', '$rootScope', 'Settings', '$location', function ($scope, $rootScope, Settings, $location) { |
||
37 | $scope.settings = { |
||
38 | nextcloud_host: '', |
||
39 | nextcloud_username: '', |
||
40 | nextcloud_password: '', |
||
41 | ignoreProtocol: true, |
||
42 | ignoreSubdomain: true, |
||
43 | ignorePort: true, |
||
44 | ignorePath: true, |
||
45 | generatedPasswordLength: 12, |
||
46 | remember_password: true, |
||
47 | remember_vault_password: true, |
||
48 | refreshTime: 60 |
||
49 | }; |
||
50 | $scope.errors = []; |
||
51 | |||
52 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
53 | $scope.errors = []; |
||
54 | if (settings) { |
||
55 | $scope.settings = angular.copy(settings); |
||
56 | } |
||
57 | |||
58 | $scope.get_vaults = function () { |
||
59 | if (!$scope.settings.hasOwnProperty('nextcloud_host') || !$scope.settings.hasOwnProperty('nextcloud_password') || !$scope.settings.hasOwnProperty('nextcloud_username')) { |
||
60 | return; |
||
61 | } |
||
62 | PAPI.username = $scope.settings.nextcloud_username; |
||
63 | PAPI.password = $scope.settings.nextcloud_password; |
||
64 | PAPI.host = $scope.settings.nextcloud_host; |
||
65 | |||
66 | PAPI.getVaults(function (vaults) { |
||
67 | $scope.errors = []; |
||
68 | var save_btn = jQuery('#save'), |
||
69 | login_required = jQuery('.login-req'); |
||
70 | if(vaults.hasOwnProperty('error')){ |
||
71 | var errors = 'Invalid response from server: ['+ vaults.result.status +'] '+ vaults.result.statusText; |
||
72 | $scope.errors.push(errors); |
||
73 | login_required.hide(); |
||
74 | save_btn.hide(); |
||
75 | $scope.$apply(); |
||
76 | return; |
||
77 | |||
78 | } |
||
79 | login_required.show(); |
||
80 | save_btn.show(); |
||
81 | $scope.vaults = vaults; |
||
82 | $scope.$apply(); |
||
83 | |||
84 | }); |
||
85 | }; |
||
86 | |||
87 | $scope.$watch('[settings.nextcloud_host, settings.nextcloud_username, settings.nextcloud_password]', function(){ |
||
88 | if ($scope.settings.nextcloud_host && $scope.settings.nextcloud_username && $scope.settings.nextcloud_password) { |
||
89 | $scope.get_vaults(); |
||
90 | } |
||
91 | }, true); |
||
92 | |||
93 | if ($scope.settings.nextcloud_host && $scope.settings.nextcloud_username && $scope.settings.nextcloud_password) { |
||
94 | $scope.get_vaults(); |
||
95 | } |
||
96 | $scope.$apply(); |
||
97 | }); |
||
98 | |||
99 | $scope.saving = false; |
||
100 | $scope.saveSettings = function () { |
||
101 | $scope.errors = []; |
||
102 | var settings = angular.copy($scope.settings); |
||
103 | try{ |
||
104 | /** global: PAPI */ |
||
105 | PAPI.decryptString(settings.default_vault.challenge_password, settings.vault_password); |
||
106 | } catch (e){ |
||
107 | $scope.errors.push('Invalid vault key!'); |
||
108 | return; |
||
109 | } |
||
110 | |||
111 | $scope.saving = true; |
||
112 | API.runtime.sendMessage(API.runtime.id, {method: "saveSettings", args: settings}).then(function () { |
||
113 | setTimeout(function () { |
||
114 | window.location = '#!/'; |
||
115 | $scope.saving = false; |
||
116 | },750); |
||
117 | }); |
||
118 | }; |
||
119 | |||
120 | |||
121 | $scope.cancel = function () { |
||
122 | window.location = '#!/'; |
||
123 | }; |
||
124 | }]); |
||
125 | }()); |
||
127 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.